package com.aauedu.springboot.config;

import com.aauedu.springboot.Listener.Listener_;
import com.aauedu.springboot.filter.Filter_;
import com.aauedu.springboot.servlet.Servlet_;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

/**
 * RegisterConfig_:是一个配置类
 * proxyBeanMethods = true：默认是单实例返回
 *
 */
@Configuration()
public class RegisterConfig_ {
    //已使用RegistrationBean方式注入
    //注入Bean

    @Bean
    public ServletRegistrationBean servlet_() {
        //创建原生的Servlet对象
        Servlet_ servlet_ = new Servlet_();
        //把servlet_对象关联到ServletRegistrationBean  对象
        //"/servlet01", "/servlet02" 就是注入的Servlet的url-pattern
        return new ServletRegistrationBean(servlet_, "/servlet01", "/servlet02");
    }

    //注入filter
    @Bean
    public FilterRegistrationBean filter_() {
        //创建原生的filter对象
        Filter_ filter_ = new Filter_();
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(filter_);
        //设置filter的url-pattern
        filterRegistrationBean.setUrlPatterns(Arrays.asList("/css/*", "/images/*"));
        return filterRegistrationBean;
    }

    //注入Listener
    @Bean
    public ServletListenerRegistrationBean listener_() {
        //创建原生的listener对象
        Listener_ listener_ = new Listener_();
        ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean(listener_);
        return servletListenerRegistrationBean;
    }
}
